package com.kotlin.lib

import kotlin.math.sqrt

fun main() {
    val max = 100
    /*var sigin = false
    for (i in 3..max step 2) {
        sigin = true
        for (j in 2..sqrt(i.toDouble()).toInt()) {
            if (i % j == 0) {
                sigin = false
                break
            }
            if (sigin) println("  $i")
        }
    }*/

    println("${getMaxPrimeNumber(max)}")
}

private fun getMaxPrimeNumber(number: Int): Int {
    var sgin: Boolean
    val max = if (number % 2 != 0) number else number - 1
    loop@ for (i in max.downTo(3) step 2) {
        sgin = true
        val middle = sqrt(i.toDouble()).toInt()
        for (j in 2..middle) {
            if (i % j == 0) {
                sgin = false
                break
            }

        }
        if (sgin) {
            println("   $i")
            return i
        }
    }
    return -1
}